package cn.tedu.imop.marketing.dao.repository.impl;

import cn.tedu.imop.common.context.PageContext;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.common.utils.PageInfoToPageDataConverter;
import cn.tedu.imop.marketing.dao.mapper.ActivityMapper;
import cn.tedu.imop.marketing.dao.repository.ActivityRepository;
import cn.tedu.imop.marketing.entity.Activity;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ActivityRepositoryImpl implements ActivityRepository {
    private final ActivityMapper acitivtyMapper;

    public ActivityRepositoryImpl(ActivityMapper acitivtyMapper) {
        this.acitivtyMapper = acitivtyMapper;
    }
    @Override
    public int insertActivity(Activity activity) {
        return acitivtyMapper.insert(activity);
    }
    @Override
    public PageData<Activity> selectActivityList(Activity activity) {
        PageContext.startPage();
        List<Activity> activities = acitivtyMapper.selectList(activity);
        return PageInfoToPageDataConverter.convert(new PageInfo<>(activities));
    }

    @Override
    public String selectTargetCustomers(Integer activityId) {
        return acitivtyMapper.selectTargetCustomers(activityId);
    }

    @Override
    public Activity selectActivityById(Integer id) {
        return acitivtyMapper.selectById(id);
    }
}
